package com.geek.framework.study.common;


import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;

public class EncodedResource {

  private final URL url;

  private final String encoding;

  public EncodedResource(URL url) {
    this(null, url);
  }

  public EncodedResource(String encoding, URL url) {
    this.encoding = encoding;
    this.url = url;
  }

  public Reader getReader() throws IOException {
//        if (encoding != null) {
//            return new InputStreamReader(getInputStream(), this.encoding);
//        }
    return new InputStreamReader(getInputStream());
  }

  public InputStream getInputStream() throws IOException {
    return url.openStream();
  }


  public URL getUrl() {
    return url;
  }

  public String getEncoding() {
    return encoding;
  }
}